package com.example.parcelabledemo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class TestActivity extends Activity {

    private TextView mTvID, mTvName, mTvAge;

    private static final int UPDATE_UI = 0X01;

    private UIHandler mHandler = new UIHandler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_2);

        mTvID = findViewById(R.id.textview_id);
        mTvName = findViewById(R.id.textview_name);
        mTvAge = findViewById(R.id.textview_age);

        Message message = new Message();
        message.what = UPDATE_UI;
        mHandler.sendMessage(message);
    }

    private void updateUI() {
        User user = (User) getIntent().getParcelableExtra("12334567890");

        mTvID.setText(String.valueOf(user.getId()));
        mTvName.setText(user.getName());
        mTvAge.setText(String.valueOf(user.getAge()));
    }


    private class UIHandler extends Handler {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case UPDATE_UI:
                    updateUI();
                    break;
                    default:
                        break;
            }
        }
    }

}
